// pages/questionnaire/questionnaire.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav:"下一页",
    currentTab:0,
    name:"无名氏",
    sex:"男",
    birthday:"2000-06-15",
    device:[
      {name:"0",value:"台式电脑"},
      {name:"1",value:"笔记本电脑"},
      {name:"2",value:"平板电脑"},
      {name:"3",value:"智能手机"},
      {name:"4",value:"智能手表"}
    ],
    time: [
      { name: "0", value: "少于一小时" },
      { name: "1", value: "一到三小时" },
      { name: "2", value: "三到五小时" },
      { name: "3", value: "五到八小时" },
      { name: "4", value: "八小时以上" }
    ],
    deviceResult:[],
    timeResult:"少于一小时",
    opinion:""
  },
  nextTab:function(){
    var maxTab=5
    var ct = this.data.currentTab +1
    if(ct==maxTab-1){
      this.setData({nav:"请点击提交"})
      return false
    }else if(ct>=maxTab){
      this.setData({nav:"问卷结果"})
      return false
    }
    this.setData({currentTab:ct})
  },
  noMove:function(res){
    return false
  },
  dateChange:function(e){
    this.setData({birthday:e.detail.value})
  },
  formSubmit:function(e){
    var name = e.detail.value.name
    var sex = e.detail.value.sex=="male"?"男":"女"
    var birthday = e.detail.value.birthday
    var device = e.detail.value.device
    console.log(device)
    var deviceResult = []
    var time = e.detail.value.time
    var timeResult = "少于一小时"
    var opinion = e.detail.value.opinion
    for(var i = 0;i<device.length;i++){
      deviceResult.push(this.data.device[device[i]].value)
    }
    timeResult = this.data.time[time].value
    this.setData({
      currentTab:this.data.currentTab+1,
      nav:"问卷结果",
      name:name,
      sex:sex,
      birthday:birthday,
      deviceResult:deviceResult,
      timeResult:timeResult,
      opinion:opinion
    })
  },
  
})